import React, { FC } from "react";
import { Button, Space } from "antd";
import { BaseButtonProps } from "antd/es/button/button";
import { SpaceProps } from "antd/es/space";
export type ButtonType = BaseButtonProps & {
  text?: string;
  render?: (button: ButtonType) => React.ReactNode;
};
export interface ActionsProps {
  options?: ButtonType[];
  spaceProps?: SpaceProps;
  className?: string;
  style?: React.CSSProperties;
  children?: React.ReactNode;
}
const Actions: FC<ActionsProps> = (props) => {
  const { className, style, options = [], spaceProps, children } = props;

  if (!options?.length) {
    return (
      <Space className={className} style={style} {...spaceProps}>
        {children}
      </Space>
    );
  }
  return (
    <Space className={className} style={style} {...spaceProps}>
      {options?.map((item) => {
        const { text, render, ...other } = item;
        if (render) {
          return render(item);
        }
        return (
          <Button type="link" {...other}>
            {text}
          </Button>
        );
      })}
    </Space>
  );
};
export default Actions;
